package com.lvtu.monitor.quartz;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Repository;

/** 
 * @Title: SpringQuartzManager.java 
 * @Package com.lvtu.monitor.quartz 
 * @Description: TODO 
 * @author dengcheng 
 * @date 2015-5-26 下午2:27:57 
 * @version V1.0.0 
 */
@Repository
public class SpringQuartzManager {
	
//	@Autowired
	SchedulerFactoryBean schedulerFactory;
	
	public void addJob(Class<?> clazz,String cronExpression){
		//JobDetail
		
		MethodInvokingJobDetailFactoryBean jobDetailFactory= new MethodInvokingJobDetailFactoryBean();
		jobDetailFactory.setTargetClass(clazz);
		jobDetailFactory.setTargetMethod("run");
		jobDetailFactory.setConcurrent(false);

		CronTriggerFactoryBean cronTriggerFactory = new CronTriggerFactoryBean();
		cronTriggerFactory.setCronExpression(cronExpression);
		cronTriggerFactory.setJobDetail(jobDetailFactory.getObject());
		cronTriggerFactory.getObject();
	
		//List<CronTrigger> trigger = new ArrayList<CronTrigger>();
		//schedulerFactory.getScheduler().addJob(arg0, arg1)
		//Cron  conTriggerBean = 
		//schedulerFactory.gett
		//List<>
		//schedulerFactory.setTriggers(trigger);
		//schedulerFactory.getScheduler().addJob(cronTrigger.getObject(), false);
		schedulerFactory.setTriggers(cronTriggerFactory.getObject());
	}
}
